#version 320 es
precision mediump float;

uniform vec3 u_objectColor;

in vec3 v_normal;
in vec3 v_fragPos;  // 世界坐标系下的片元坐标

out vec4 FragColor;
float near = 0.1;
float far  = 100.0;

float LinearizeDepth(float depth)
{
    float z = depth * 2.0 - 1.0; // back to NDC
    return (2.0 * near * far) / (far + near - z * (far - near));
}

// gles 没有内置pow函数

void main() {
    // 可视化深度缓冲
    float depth = LinearizeDepth(gl_FragCoord.z) / far; // 为了演示除以 far
    FragColor = vec4(vec3(depth), 1.0);
}